package com.usian.controller;

import com.usian.message.Message;
import com.usian.service.MessageService;
import com.usian.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/app/message")
public class MessageController {
    @Autowired
    private MessageService messageService;

    @RequestMapping("/selectMessageList/{acceptId}/{sendId}")
    public Result selectMessageList(@PathVariable("acceptId") Integer acceptId,@PathVariable("sendId") Integer sendId){
        return Result.success(messageService.selectMessageList(acceptId,sendId));
    }
    @GetMapping("/find/{userid}/{type}")
    public Result find(@PathVariable("userid") Integer userid,@PathVariable("type")Integer type){
        List<Message> list = messageService.find(userid,type);
        return Result.success(list);
    }
    @PostMapping("/send/{sendId}/{acceptId}")
    public Result sendMessage(
            @PathVariable("sendId") Integer sendId,
            @PathVariable("acceptId") Integer acceptId,
            @RequestBody Message message) {
        Message message1 = new Message(null, sendId, acceptId, message.getMessage(), new Date());
        return Result.success(messageService.send(message1));
    }
}
